<template>
  <view v-if="verified" class="index-wrapper">
    <scroll-view class="info-wrapper" :scroll-y="true">
      <u-cell-group>
        <u-cell-item
          v-for="(item, index) in InfoList"
          :key="index"
          :title="item.moduleName"
          @click="onModule(item)"
        >
          <span v-if="item.necessary" slot="icon" class="required">*</span>
        </u-cell-item>
      </u-cell-group>
    </scroll-view>
    <view class="save">
      <div class="btn" @click="save">提交</div>
    </view>
  </view>
  <view v-else class="bg">
    <view class="tip-wrapper">
      <view class="tippic">
        <img src="/employee/img/hetongrenzheng.png" alt />
      </view>
      <p class="tips">请先完成实名认证，再进行个人信息补充</p>
      <button class="btn btn-auth" @click="goAuthentication">立即认证</button>
    </view>
  </view>
</template>
<script>
import { mapState } from "vuex";
import {
  listCompanyModuleCodes,
  checkEmpFieldValue,
  getEmpFieldValue
} from "@/services/employee";
export default {
  name: "",
  data() {
    return {
      InfoList: []
    };
  },
  computed: {
    ...mapState(["site", "employee", "user"]),
    verified() {
      return this.site.verified;
    }
  },

  // 页面周期函数--监听页面显示(not-nvue)
  onShow() {
    this.getlistCompanyModuleCodes();
  },
  methods: {
    save() {
      checkEmpFieldValue({
        empInfoId: this.site.employeeId,
        companyId: this.site.companyId
      })
        .then(result => {
          uni.showToast({
            title: "信息更新成功",
            icon: "none",
            duration: 1500
          });
          setTimeout(() => {
            uni.reLaunch({
              url: "/pages/index/index"
            });
          }, 1000);
        })
        .catch(err => {
          console.log("🚀 ~ file: index.vue ~ line 53 ~ save ~ err", err);
        });
    },
    onModule(data) {
      uni.setStorageSync("module_data", data);
      if (data.multiple) {
        uni.navigateTo({
          url: "/employee/entranceList"
        });
      } else {
        uni.navigateTo({
          url: "/employee/entrance"
        });
      }
    },
    fieldList(moduleCode) {
      const data = {
        empInfoId: this.site.employeeId,
        companyId: this.site.companyId,
        moduleCode: moduleCode[0].moduleCode
      };
      getEmpFieldValue(data)
        .then(res => {
           console.log("debug log --> ", res.data);
          uni.setStorageSync('moduleCodeName',res.data.name)
           console.log("file[this.ingNum].path", uni.getStorageSync('moduleCodeName'));
        })
        .catch(err => {
          console.log("debug log 失败--> ", err);
        });
    },
    getlistCompanyModuleCodes() {
      listCompanyModuleCodes({
        empInfoId: this.site.employeeId,
        companyId: this.site.companyId
      })
        .then(res => {
          this.InfoList = res;
          this.fieldList(res);
        })
        .catch(err => {
          console.log("debug log --> ", err);
        });
    },
    goAuthentication() {
      uni.navigateTo({
        url: "/authorize/realname"
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.bg {
  width: 100%;
  overflow-x: hidden;
  min-height: 100vh;
  background: rgba(250, 251, 251, 1);
}
.required {
  color: red;
}
.save {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  background-color: #ffffff;
  .btn {
    width: 80%;
    height: 45px;
    line-height: 45px;
    text-align: center;
    background-color: $theme;
    font-size: 18px;
    color: #fff;

    border-radius: 10px;
  }
}
</style>
